<template>
  <a-spin :spinning="confirmLoading">
    <div class="container">
      <div class="auto">
        <div class="rule_wrap">
          <div class="rule_bar clearfix">
            <a-select v-model="articlType" style="width: 150px; float: right;">
              <a-select-option value="1">最新</a-select-option>
              <a-select-option value="2">最热门</a-select-option>
              <a-select-option value="3">本月</a-select-option>
            </a-select>
          </div>
          <a-row class="rule_list clearfix" v-if="articleList.length">
            <div class="item wow fadeInUp animated" data-wow-delay="0.1s" v-for="item in articleList" :key="item.id">
              <router-link :to="{path: '/noticeNotice/noticeNoticeDetail', query: {noticeId: item.id}}">
<!--                <a href="#" class="imgbox">-->
<!--                  <img :src="item.titleImgUrl" :alt="item.title" class="img" style="height: 230px;"/>-->
<!--                </a>-->
                <div class="info">
                  <a href="#" class="title ellipsis">{{item.title}}</a>
                  <div class="txt clamp" v-html="item.subtitle"></div>
                </div>
                <div class="bot clearfix">
                  <em class="tag" v-for="tags in item.articleLabels" :key="tags.id">{{tags.name}}</em>
                  <span class="date fr">{{item.createDate}}</span>
                </div>
              </router-link>
            </div>
          </a-row>
          <a-row v-else class="rule_list clearfix">
            <div class="no-data"><a-icon type="frown-o"/>暂无数据</div>
          </a-row>
          <a-row v-if="articleList.length > 0" style="margin-top: 10px;">
            <a-col>
              <a-pagination
                style="float: right;"
                v-model="pageNo"
                :page-size-options="pageSizeOptions"
                :total="total"
                show-size-changer
                :page-size="pageSize"
                :showSizeChanger="true"
                :showQuickJumper="false"
                :show-total="showTotal"
                @showSizeChange="onShowSizeChange"
                @change="currentChage"
              >
              </a-pagination>
            </a-col>
          </a-row>
        </div>

      </div>
    </div>
  </a-spin>
</template>

<script>
import '../../public/css/style.css';
import { getAction } from '@/api/manage'
export default {
  name: 'NoticeNotice',
  beforeRouteEnter (to, from, next) {
    window.scrollTo(0, 0);
    next();
  },
  data () {
    return {
      confirmLoading: false,
      articlType: '1',
      articleList: [],
      pageSizeOptions: ['6', '12', '18', '24', '30'],
      pageNo: 1,
      pageSize: 6,
      total: 50,
    };
  },
  watch: {
    articlType: {
      // immediate: true,
      handler(val) {
        this.getArticleList()
      }
    }
  },
  created() {
    this.getArticleList()
  },
  methods: {
    onShowSizeChange(pageNo, pageSize) {
      this.pageNo = 1
			this.pageSize = pageSize
			this.getArticleList()
    },
    currentChage(page, pageSize) {
			this.pageSize = pageSize
			this.getArticleList()
    },
    showTotal(total, range) {
			return range[0] + "-" + range[1] + " 共" + total + "条"
		},
    getArticleList() {
      let self = this
      let params = {
        limit: self.pageSize,
        page: self.pageNo,
        columnId: '3',
        type: '2'
      }
      if(this.articlType) {
        params.sort = this.articlType
      }
      self.confirmLoading = true
      getAction('/article/list', params).then(res => {
        if(res.code == 0) {
          self.articleList = [...res.result.list]
          self.pageNo = res.result.currPage
					self.total = res.result.totalCount
        } else {
          self.$message.error(res.msg)
        }
      }).finally(() => {
        self.confirmLoading = false
      })
    }
  }
};
</script>

<style lang="less" scoped>
  .no-data {
      color: rgba(0, 0, 0, .25);
      text-align: center;
      line-height: 64px;
      font-size: 16px;

      i {
        font-size: 24px;
        margin-right: 16px;
        position: relative;
        top: 3px;
      }
    }
</style>
